package com.zzyy.study.controller;

import cn.hutool.core.util.IdUtil;
import com.zzyy.study.annotations.RedisLimitAnnotation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther zzyy
 * @create 2024-03-07 10:31
 */
@Slf4j
@RestController
public class RedisLimitController
{
    /**
     * Redis+Lua脚本+AOP+反射+自定义注解，打造我司内部基础架构限流组件
     * http://localhost:24310/redis/limit/test
     *
     * 在redis中，
     * key = redis-limit:test
     * Value = permitsPerSecond设置的具体值
     * 过期时间 = expire设置的具体值
     */
    @GetMapping("/redis/limit/test")
    @RedisLimitAnnotation(key = "redis-limit:test", permitsPerSecond = 2, expire = 1, msg = "当前排队人数较多，请稍后再试！")
    public String redisLimit()
    {
        return "正常业务返回，订单流水："+IdUtil.fastUUID();
    }
}
